let { api } = require("./../../utils/api.js");
Page({
  data: {},

  // 验证登陆
  loginCheck: function(e) {
    const that = this;
    let username, password;
    username = e.detail.value.username;
    password = e.detail.value.password;
    console.log(username + ":" + password);
    if (username != "" && password != "") {
      wx.request({
        url: api + "login.do",
        method: "POST",
        data: {
          username,
          password,
          role: 2
        },
        success: function(res) {
          console.log(res.data);
          if (res.data.status === 1) {
            wx.showToast({
              title: "登陆中...",
              icon: "loading",
              duration: 1000,
              success: function() {
                setTimeout(function() {
                  wx.navigateTo({
                    url: "../admin/admin"
                  });
                }, 1000);
                wx.setStorageSync("isLogin", true);
              }
            });
          } else {
            wx.showToast({
              title: "账号/密码错误，请重试!",
              icon: "none",
              duration: 2000
            });
          }
        },
        fail: function(res) {
          wx.showToast({
            title: "登录失败，稍后重试",
            icon: "none",
            duration: 2000
          });
        }
      });
    } else {
      wx.showToast({
        title: "输入不能为空！",
        image: "./../../images/public/tips.png",
        duration: 1000
      });
    }
  }
});
